package com.hdrx.fundhelper.utils;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.LocationTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;

import java.io.IOException;

/**
 * @author: houdx
 * @description:
 * @date: 2023/7/13 16:55
 */
public class ReadPdf {
    public static void main(String[] args) throws IOException {
        String pdfPath = "E:/PMI Certfication.pdf";
        String text = "houdongxu";
        StringBuilder result = new StringBuilder();
        PdfReader reader = new PdfReader(pdfPath);
        int countPage = reader.getNumberOfPages();
        for(int i=1;i<=countPage;i++){
            LocationTextExtractionStrategy strategy = new LocationTextExtractionStrategy();
            String textFromPage = PdfTextExtractor.getTextFromPage(reader, i, strategy);
            if (textFromPage.contains(text)){

            result.append(PdfTextExtractor.getTextFromPage(reader, i));
        }
        reader.close();
    }
}}
